//
//  CJServiceCell.m
//  NewPro
//
//  Created by RYX on 2019/2/21.
//  Copyright © 2019 何荧红. All rights reserved.
//

#import "CJServiceCell.h"
#import "HGOrientationLabel.h"

@interface CJServiceCell()

@property (nonatomic,weak) UIImageView *im;
@property (nonatomic,weak) HGOrientationLabel *la;
@property (nonatomic,weak) UILabel *nameLa;

@end

@implementation CJServiceCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setUI];
    }
    
    return self;

}

- (void)setUI{
    
    UIImageView *im = [[UIImageView alloc] init];
//    im.layer.cornerRadius = 5;
//    im.layer.masksToBounds = YES;
//    im.layer.borderWidth = 2;
//    im.layer.borderUIColor = [UIColor colorWithHexString:@"E4E2E2"];
    im.image = [UIImage imageNamed:@"kefuImg"];
    self.im = im;
    [self addSubview:im];
    
//    UILabel *nameLa = [[UILabel alloc] init];
//    self.nameLa = nameLa;
//    nameLa.textColor = BLUECOLOR;
//    nameLa.font = [UIFont systemFontOfSize:13];
//    [self addSubview:nameLa];
    
    HGOrientationLabel *la = [[HGOrientationLabel alloc] init];
    self.la = la;
    la.preferredMaxLayoutWidth = (ScreenWidth - 58 * 2);
    [la setContentCompressionResistancePriority:UILayoutPriorityRequired
                                        forAxis:UILayoutConstraintAxisHorizontal];
    [la setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
    la.numberOfLines = 0;
    [la textAlign:^(HGMaker *make) {
        make.addAlignType(textAlignType_left).addAlignType(textAlignType_top);
    }];
    [self addSubview:la];
    
    UIView *bgView = [[UIView alloc] init];
    bgView.backgroundColor = UIColor.whiteColor;
    bgView.layer.cornerRadius = 5;
    [self insertSubview:bgView belowSubview:la];
    
    [im mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.height.width.mas_equalTo(40);
        make.left.top.equalTo(self).offset(8);
    }];

//    [nameLa mas_makeConstraints:^(MASConstraintMaker *make) {
//
//        make.left.equalTo(im.mas_right).offset(8);
//        make.centerY.equalTo(im);
//    }];
    
    [la mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(im.mas_top).offset(12);
        make.left.equalTo(im.mas_right).offset(20);
        make.bottom.equalTo(self).offset(-20);
    }];
    
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(im.mas_top);
        make.left.equalTo(im.mas_right).offset(10);
        make.bottom.equalTo(la.mas_bottom).offset(12);
        make.right.equalTo(la.mas_right).offset(8);
    }];
    
}

- (void)setModel:(ChatModel *)model{
    
    //富文本属性
    NSMutableDictionary *textDict = [NSMutableDictionary dictionary];
    //基本属性设置
    //字体颜色
    textDict[NSForegroundColorAttributeName] = [UIColor blackColor];
    //字号大小
    textDict[NSFontAttributeName] = [UIFont systemFontOfSize:15.0];
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    
    //行间距
//    paraStyle.lineSpacing = 1.0;
    
    //首行文本缩进
    //    paraStyle.firstLineHeadIndent = 20.0;
    
    //使用
    //文本段落样式
    textDict[NSParagraphStyleAttributeName] = paraStyle;
    //字间距(字符串)
    textDict[NSKernAttributeName] = @(1);
    //赋值
    self.la.attributedText = [[NSAttributedString alloc] initWithString:model.content attributes:textDict];
    
//    self.im.image = [UIImage imageNamed:model.img];
//    self.la.text = model.content;
//    self.nameLa.text = model.name;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
